package com.dkd.manage.controller;

import com.dkd.common.core.domain.R;
import com.dkd.manage.pojo.dto.NodeQueryListDto;
import com.dkd.manage.pojo.entity.Node;
import com.dkd.manage.pojo.vo.NodeVo;
import com.dkd.manage.result.PageResult;
import com.dkd.manage.service.NodeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

@RestController
@Slf4j
@Api(tags = "点位管理相关接口")
@RequestMapping("/manage/node")
public class NodeController {

    @Autowired
    private NodeService nodeService;

    @ApiOperation("分页查询点位列表")
    @PreAuthorize("@ss.hasPermi('manage:node:list')")
    @GetMapping("/list")
    public R<PageResult<NodeVo>> list(NodeQueryListDto nodeQueryListDto) {
        log.info("分页查询点位列表：{}", nodeQueryListDto);
        PageResult<NodeVo> result = nodeService.list(nodeQueryListDto);
        return R.ok(result);
    }

    @ApiOperation("新增点位")
    @PreAuthorize("@ss.hasPermi('manage:node:add')")
    @PostMapping
    public R<Integer> add(@RequestBody Node node) {
        log.info("新增点位：{}", node);
        Integer rows = nodeService.add(node);
        return R.ok(rows);
    }

    @ApiOperation("根据id查询点位")
    @PreAuthorize("@ss.hasPermi('manage:node:query')")
    @GetMapping("/{id}")
    public R<Node> getNodeById(@PathVariable Long id) {
        log.info("根据id查询点位：{}", id);
        Node node = nodeService.getNodeById(id);
        return R.ok(node);
    }

    @ApiOperation("修改点位")
    @PreAuthorize("@ss.hasPermi('manage:node:edit')")
    @PutMapping
    public R<Integer> edit(@RequestBody Node node) {
        log.info("修改点位：{}", node);
        Integer rows = nodeService.edit(node);
        return R.ok(rows);
    }

    @ApiOperation("根据id删除点位")
    @PreAuthorize("@ss.hasPermi('manage:node:remove')")
    @DeleteMapping("/{ids}")
    public R<Integer> deleteNodeById(@PathVariable Long[] ids) {
        log.info("根据id删除点位：{}", ids);
        Integer rows = nodeService.deleteNodeById(ids);
        return R.ok(rows);
    }

}
